package testJdk.thread.pool.testSqlCallable;

import java.lang.reflect.Method;
import java.util.concurrent.Callable;

/**
 * 在线程池里，通过反射，执行查询语句
 */
public class SqlCallableTask<T> implements Callable {

    T t;
    String methodName;
    Long tId;

    public SqlCallableTask(T t, String methodName, Long tId) {
        this.t = t;
        this.methodName = methodName;
        this.tId = tId;
    }

    @Override
    public Object call() throws Exception {
        Class<?> aClass = t.getClass();
        Method method = aClass.getMethod(methodName, Long.class);
        System.out.println("method:" + method);
        System.out.println("tId-of-call:" + tId);

        Object result = method.invoke(t, tId);
        System.out.println("result-of-call:" + result);

        return result;
    }
}
